# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=weechat
pkgver=2.9
pkgrel=0
pkgdesc="A fast, light, extensible ncurses-based chat client"
url="https://weechat.org"
arch="all"
options="!check" # test suite runs "sudo make install"
license="GPL-3.0-or-later"
depends_dev="asciidoctor
	cmake
	gettext-dev
	ncurses-dev
	gnutls-dev
	libgcrypt-dev
	curl-dev
	aspell-dev
	lua-dev
	perl-dev
	python3-dev
	ruby-dev
	zlib-dev
	"

makedepends="$depends_dev"
subpackages="$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-spell:_plugin
	$pkgname-lua:_plugin
	$pkgname-perl:_plugin
	$pkgname-python:_plugin
	$pkgname-ruby:_plugin
	"

source="https://www.weechat.org/files/src/weechat-$pkgver.tar.gz"

# secfixes:
#   1.7.1-r0:
#     - CVE-2017-8073
#   1.9.1-r0:
#     - CVE-2017-14727
#   2.7.1-r0:
#     - CVE-2020-8955

build() {
	mkdir -p build
	cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DENABLE_MAN=ON \
		-DENABLE_TCL=OFF \
		-DENABLE_GUILE=OFF \
		-DENABLE_JAVASCRIPT=OFF \
		-DENABLE_PHP=OFF
	make
}

package() {
	cd "$builddir"/build
	make DESTDIR="$pkgdir/" install
}

_plugin() {
	local _name=${subpkgname#*-}
	local _dir=usr/lib/weechat/plugins

	pkgdesc="WeeChat $_name plugin"
	depends="weechat"

	# as of 2.5 aspell has been renamed to spell on weechat upstream
	# since it now supports enchant as well, rename the subpackage and
	# replace the old one
	if [ "$_name" = spell ]; then
		replaces="$pkgname-aspell"
		provides="$pkgname-aspell=$pkgver-r$pkgrel"
	fi

	mkdir -p "$subpkgdir"/$_dir
	mv "$pkgdir"/$_dir/"$_name".so "$subpkgdir"/$_dir
}

check() {
	./tools/build-test.sh cmake
}

sha512sums="975f5b7b6ed44be1ccd5b9b157c38ce5a3ce7319e873d7913b80b23d619351fd8edb35a29e6d488e31ae67b5ad70c1933dcea1dfd914ab8c1a10b7810723bd78  weechat-2.9.tar.gz"
